package org.airline.entity;

import java.util.List;

@SuppressWarnings("all")
public class PageBean {

	private List list; // 记录列表
	private int allRow; // 总记录数
	private int totalPage; // 总页数
	private int currentPage; // 当前页码
	private int pageSize; // 每页记录数
	private boolean isFirstPage; // 是否为首页
	private boolean isLastPage; // 是否为最后一页
	private boolean hasPreviousPage; // 是否有前一页
	private boolean hasNextPage; // 是否有下一页
	private int[] pageNumbers; // 页码

	// 初始化分页信息
	public void init() {
		this.isFirstPage = this.isFirstPage();
		this.isLastPage = this.isLastPage();
		this.hasPreviousPage = this.isHasPreviousPage();
		this.hasNextPage = this.isHasNextPage();
	}

	// 计算总页数,静态方法,供外部直接通过类名调用
	public static int countTotalPage(final int pageSize, final int allRow) {
		int totalPage = (allRow + pageSize - 1) / pageSize;
		return totalPage;
	}

	// 计算当前页开始记录
	public static int countOffset(final int pageSize, final int currentPage) {
		final int offset = pageSize * (currentPage - 1);
		return offset;
	}

	// 计算当前页,若为0或者请求的URL中没有"?page=",则用1代替
	public static int countCurrentPage(int page) {
		final int curPage = (page == 0 ? 1 : page);
		return curPage;
	}

	public boolean isFirstPage() {
		return currentPage == 1;
	}

	public void setFirstPage(boolean isFirstPage) {
		this.isFirstPage = isFirstPage;
	}

	public boolean isLastPage() {
		return currentPage == totalPage;
	}

	public void setLastPage(boolean isLastPage) {
		this.isLastPage = isLastPage;
	}

	public boolean isHasPreviousPage() {
		return currentPage != 1;
	}

	public void setHasPreviousPage(boolean hasPreviousPage) {
		this.hasPreviousPage = hasPreviousPage;
	}

	public boolean isHasNextPage() {
		return currentPage != totalPage;
	}

	public void setHasNextPage(boolean hasNextPage) {
		this.hasNextPage = hasNextPage;
	}

	public List getList() {
		return list;
	}

	public void setList(List list) {
		this.list = list;
	}

	public int getAllRow() {
		return allRow;
	}

	public void setAllRow(int allRow) {
		this.allRow = allRow;
	}

	public int getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int[] getPageNumbers() {
		return pageNumbers;
	}

	public void setPageNumbers(int[] pageNumbers) {
		this.pageNumbers = pageNumbers;
	}
	
}
